package com.hzncc.flowable_diboot.contract.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import com.diboot.core.service.impl.BaseServiceImpl;

import com.hzncc.flowable_diboot.contract.entity.ContractTeam;
import com.hzncc.flowable_diboot.mapper.ContractTeamMapper;
import com.hzncc.flowable_diboot.contract.service.ContractTeamService;

import java.util.ArrayList;
import java.util.List;


/**
* 合同团队 相关Service实现类
* @author MyName
* @version 1.0
* @date 2024-08-22
* Copyright © MyCorp
*/
@Slf4j
@Service
public class ContractTeamServiceImpl extends BaseServiceImpl<ContractTeamMapper, ContractTeam> implements ContractTeamService {

    /**
     * 根据合同id查询团队合同
     * @param beforeId
     * @return
     */
    @Override
    public List<ContractTeam> getTeamsByContractId(String beforeId) {
        return lambdaQuery().eq(ContractTeam::getContractId, beforeId).list();
    }

    /**
     * 查询团队合同
     *
     * @param userIds
     * @return
     * @author 陈广煜
     * @date 2024-09-19
     */
    public List<String> getTeamContract(List<String> userIds) {
        QueryWrapper<ContractTeam> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().select(ContractTeam::getContractId).in(ContractTeam::getMemberId, userIds);
        List<ContractTeam> contractTeams = getEntityList(queryWrapper);
        List<String> ids = new ArrayList<>(contractTeams.stream().map(ContractTeam::getContractId).distinct().toList());
        ids.add("0"); // 防止ids为空
        return ids;
    }
}